public class Example {
    public static int factor(int n) {
        if (n == 1) {
            return 1;
        }
        return n * factor(n - 1); // factor 调用函数自身
    }
    public static void main(String[] args) {
        int n = 5;
        int ret = factor(n);
        System.out.println("ret = " + ret);
    }

   /* public static int add(int x, int y){
        return x + y;
    }
    public static double add(double x, double y){
        return x + y;
    }
    public static void main(String[] args) {
        add(1,2);
        add(1.5, 2.5);
        System.out.println(add(1,2));
        System.out.println(add(1.5, 2.5));
    }*/
    /*// 注意：两个方法如果仅仅只是因为返回值类型不同，是不能构成重载的
        public static void main(String[] args) {
            int a = 10;
            int b = 20;
            int ret = add(a, b);
            System.out.println("ret = " + ret);
        }
        public static int add(int x, int y) {
            return x + y;
        }
        public static double add(int x, int y) {
            return x + y;
        }

    public static int add1(int x, int y){
       return x+y;
    }
    public static double add2(double a, double b, double c) {
        return a + b + c;
    }
   public static void add(int x, int y){
         System.out.println("x= " + x +"," + "y= " + y);
         System.out.println("x+y="+" "+(x+y));
     }
    public static void main1(String[] args) {

        int ret2 = add1(33,33);
        System.out.println(ret2);
        double ret1 = add2(1.3,1.4,6.6);
        System.out.println(ret1);
    }*/
}
